package com.netcracker.educenter.filestorage.servlets.security.authentication;

import org.apache.log4j.Logger;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(urlPatterns = "/Exit")
public class ExitServlet extends HttpServlet {

    private static final Logger log = Logger.getLogger(ExitServlet.class);

    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) {

        HttpSession session = request.getSession();
        session.removeAttribute("authorized_user");
        session.invalidate();

        try {
            response.sendRedirect(request.getContextPath());
        } catch (IOException e) {
            log.error("Cannot go to page", e);
        }
    }
}
